package top.someapp.dxf2dsvg.dxf;

import java.util.regex.Pattern;

/**
 * dxf文件中的最小可读单位, 一般包含“组码”和“组码值”
 *
 * @author zwz
 * Created on 2020-04-17
 * @see <a href="http://help.autodesk.com/view/OARX/2018/CHS/?guid=GUID-2553CF98-44F6-4828-82DD-FE3BC7448113">
 * 组码值类型参考 (DXF)</a>和
 * <a href="http://help.autodesk.com/view/OARX/2018/CHS/?guid=GUID-3F0380A5-1C15-464D-BC66-2C5F094BCFB9">
 * 按数字次序排列的 DXF 组码参考</a>
 */
public class Item {
    private static final String lineSeparator = "\r\n";
    public static final Pattern LEFT_PADDING_REG = Pattern.compile("\\s+[0-9]+");

    /**
     * 组码
     */
    public final int code;
    /**
     * 组码值
     */
    public final String value;
    private final String raw;

    public Item(String code, String value) {
        this.code = Integer.valueOf(code.trim());
        this.value = value;
        this.raw = code + lineSeparator + value;
    }

    public boolean isCodeStartWithPadding() {
        char first = raw.charAt(0);
        return !(first >= '0' && first <= '9');
    }

    @Override
    public String toString() {
        return "Item{" +
                "code=" + code +
                ", value='" + value + '\'' +
                '}';
    }
}
